<template> 	
  <div class="page">
	<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">
						
						<div class="layui-card-body">							
							<div class="layui-form" lay-filter="">
								
								<div class="layui-form-item"><div class="layuitj1">以下带 <i class="red">*</i> 的为必填项</div></div>
									
								<div class="layui-form-item">
									<div class="layui-inline">
									    <label class="layui-form-label"><i class="red">*</i>登陆账号</label>
									    <div class="layui-input-inline" >
									        <input type="text" name="name" placeholder="请输入登陆账号"  v-model="itemData.name" autocomplete="off" class="layui-input a" maxlength="11">
									    </div>	
									    <div class="layuitj">提交后不能更改</div>
								  </div>
								</div> 														    
						    <div class="layui-form-item">
									<div class="layui-inline">
									    <label class="layui-form-label"><i class="red">*</i>昵称</label>
									    <div class="layui-input-inline" >
									        <input type="text" name="nickName" placeholder="请输入昵称"  v-model="itemData.nickName" autocomplete="off" class="layui-input a" maxlength="11">
									    </div>										   
								  </div>
								</div>
						    <div class="layui-form-item">
									<div class="layui-inline">
									    <label class="layui-form-label"><i class="red">*</i>登陆密码</label>
									    <div class="layui-input-inline" >
									        <input type="password" name="password" placeholder="请输入登陆密码"  v-model="itemData.password" autocomplete="off" class="layui-input a" maxlength="6">
									    </div>										   
								  </div>
								</div>
						    <div class="layui-form-item">
									<div class="layui-inline">
									    <label class="layui-form-label"><i class="red">*</i>支付密码</label>
									    <div class="layui-input-inline" >
									        <input type="password" name="payPassword" placeholder="请输入支付密码"  v-model="itemData.payPassword" autocomplete="off" class="layui-input a" maxlength="6">
									    </div>										   
								  </div>
								</div>
						    <div class="layui-form-item">
									<div class="layui-inline">
									    <label class="layui-form-label">用户类型</label>
									    <div class="layui-input-inline">
												<select name="userTypeId" lay-filter="userTypeId"  v-model="itemData.userTypeId">
													<option :value="item.id" v-for="item in userlist">{{item.name}}</option>													 
												</select>
											</div>												   
								  </div>
								</div>
						     <div class="layui-form-item">
									<div class="layui-inline">
									    <label class="layui-form-label">手机号</label>
									    <div class="layui-input-inline" >
									        <input type="number" name="mobile"  placeholder="请输入手机号"  v-model="itemData.mobile" autocomplete="off" class="layui-input" maxlength="11">
									    </div>										   
								  </div>
								</div>
								<div class="layui-form-item">
									<div class="layui-inline">
									    <label class="layui-form-label">邮箱</label>
									    <div class="layui-input-inline">
									        <input type="text" name="email"  placeholder="请输入邮箱"  v-model="itemData.email" autocomplete="off" class="layui-input" maxlength="">
									    </div>										   
								  </div>
								</div>
								<div class="layui-form-item">
									<div class="layui-inline">
									    <label class="layui-form-label">状态</label>
									    <div class="layui-input-inline">
												<select name="status" lay-filter="status"  v-model="itemData.status">
													<option value="1">启用</option>	
												  <option value="2">禁用</option>												  
												</select>
											</div>											   
								  </div>
								</div>
								<div class="layui-form-item">
									<div class="layui-input-block">
										<button class="layui-btn layui-btn-normal" lay-submit lay-filter="setmyinfo" @click="confirmOk">确定</button>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>		
		<input type="hidden" id='id'/>
  </div> 
</template>
<script>
export default {	
  name: 'operatoradd',  
  data () {
    return { 
    	id:'',
    	curindex:1, //页数    	    	    	
    	itemData:{
    		status:'1',
    		mobile:"",
    		email:""
    	},
    	where:'',//编辑时传的2
			userlist:[],
			userTypeId:'',  
			
			
    }
  },
  mounted(){ 
  	var _this = this;
   	_this.getuserType();
	  window.getdates = this.getdates;  
  },
  methods: {  	
		getdates:function(data){		
			var _this = this; 			
			_this.id=data.id;
			_this.where=data.where;
//			var dates={
//					id:_this.id,	
//					where:_this.where,
//			}			
			var url="/huanxinsong/account/editJson/"+_this.id						
			ajaxRequest(url,'GET','json','',function(ret,err){
				//alert(url+"///"+JSON.stringify(ret))
				  _this.itemData=ret.content; 
				  _this.userTypeId=ret.content.userTypeId;
				 $('iput[name="name"]').attr('disabled','disabled')
				 //_this.timeData=FormatDate(ret.createAt,3);				  
				 
			})			
		},
		getuserType:function(){
			var _this=this;
			var url="/huanxinsong/account/adminOperatorList"			         
			ajaxRequest(url,'GET','json','',function(ret,err){
				//alert(url+"///"+JSON.stringify(ret))
				  _this.userlist=ret.content; 
				  setTimeout(function(){
				  	
				  	_this.itemData.userTypeId=_this.userTypeId;
				  },300)

			})
		},
		confirmOk:function(){
			var _this=this;				
			var len = $(".a").length;
			for(var i = 0; i < len; i++) {
				if($(".a").eq(i).val() == ''||$(".a").eq(i).val()<=0) {
					var msg = $(".a").eq(i).attr("placeholder");
					layer.msg('请输入正确的'+msg);
					return;
				}
			}	
			//alert(JSON.stringify(_this.itemData))		
//			if(_this.itemData.mobile!=""){				
//				if(!(/^(?:13\d|15\d|18\d)\d{5}(\d{3}|\*{3})$/.test(mobile))){       
//					layer.msg("请输入正确的手机号"); 
//					return;
//				}
//		  }
//			if(_this.itemData.email!=""){
//				if(!/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(email)){
//					layer.msg("请输入正确的邮箱地址");
//					return;
//				}
//			}	
	    if(_this.id){
	     	var dates={
	     		 id:_this.itemData.id,
					 name:_this.itemData.name,
					 nickName:_this.itemData.nickName,
					 password:_this.itemData.password,
					 payPassword:_this.itemData.payPassword,
					 userType:_this.itemData.userTypeId,
					 mobile:_this.itemData.mobile,
					 email:_this.itemData.email,
					 status:_this.itemData.status,				
				}
	    }else{
				var dates={
					 name:_this.itemData.name,
					 nickName:_this.itemData.nickName,
					 password:_this.itemData.password,
					 payPassword:_this.itemData.payPassword,
					 userType:_this.itemData.userTypeId,
					 mobile:_this.itemData.mobile,
					 email:_this.itemData.email,
					 status:_this.itemData.status,				
				}
			}
		//alert(JSON.stringify(dates))	
			if(_this.id){		
				var url='/huanxinsong/account/updarteadminOperator'//编辑				
			}else{
			  var url="/huanxinsong/account/adminOperatorsubmit" //新增
			}
			ajaxRequest(url, 'GET', 'JSON', dates, function(ret, err){
				//alert(JSON.stringify(dates)+"///"+JSON.stringify(ret))
				layer.msg('操作成功！');
				setTimeout(function(){
			  	var index = parent.layer.getFrameIndex(window.name);	          	
			    parent.layer.close(index);
		      parent.location.reload(); 
	      },1000)
			})
		},
//	dotime(val){
//		return FormatDate(val);
//	}
  },
   updated:function(){
		this.isShow = true;
		var _this=this;
		layui.use('form', function(){
		  var form = layui.form;
		  form.render();
		  form.on("select(status)", function(data){										
			   _this.itemData.status = data.value
		  });
		  form.on("select(userTypeId)", function(data){	
		  	//alert(JSON.stringify(data))
			   _this.itemData.userTypeId = data.value
		  });
		});
  },

}
</script>
<style scoped>
	.red{color:#ff0000;}
	.layuitj{float:left;line-height:38px;color:#FF0000;}
	.layuitj1{margin-left:20px;}
</style>
